// int max(int * array, int len);
#include <cassert>

bool max(int * array, int len, int * result){
	if (array == nullptr || len <= 0) return false;

	*result = array[0];
	for(int i = 1; i < len; ++i){
		if(*result < array[i]) {
			*result = array[i];
		}
	}
	return true;
}

int main(){
	//regular 
	{
		int array[] = {1, 2, 3};	
		int result = 0;
		bool ok = max(array, sizeof(array)/sizeof(int), &result);
		assert(3 == result);
		assert(ok);
	}
	{
		int array[] = {1, 2, 4};	
		int result = 0;
		bool ok = max(array, sizeof(array)/sizeof(int), &result);
		assert(4 == result);
		assert(ok);
	}

	// edge 
	{
		int array[] = {3};
		int result = 0;
		bool ok = max(array, sizeof(array)/sizeof(int), &result);
		assert(3== result);
		assert(ok);
	}

	//Exception
	{
		int array[] = {};
		int result = 0;
		bool ok = max(array, sizeof(array)/sizeof(int), &result);
		assert(ok == false);
	}

	{
		int result = 0;
		bool ok = max(nullptr, 1, &result); 
		assert(ok == false);
	}

	return 0;
}
